/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-8-26 下午3:51 Created by lyyang
 */
package com.jade.modules.message.service;

import java.io.Serializable;
import java.util.Date;

import com.jade.framework.base.util.Parameters;
import com.jade.framework.base.util.SimpleParameters;


/**
 * 消息类
 *
 * @author <a href="mailto:lyyang@ceno.cn">lyyang</a>
 * @version 1.0 15-8-26 下午3:51
 */
public class Message
        implements Serializable
{
    private String id;
    //消息类型，对应具体的消息处理逻辑
    private String type = MessageConstants.DEFAULT_TYPE;
    //消息分组，用于业务对消息进行分类
    private String group;
    //对应的业务实体标识，便于业务处理
    private String fid;
    //消息创建时间
    private Date creatioTime;
    //消息定时处理时间
    private Date scheduleTime;
    //消息最大重试次数
    private int maxRetryTimes;
    //业务扩展参数
    private Parameters params;

    public String getId()
    {
        return id;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getGroup()
    {
        return group;
    }

    public void setGroup(String group)
    {
        this.group = group;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public String getFid()
    {
        return fid;
    }

    public void setFid(String fid)
    {
        this.fid = fid;
    }

    public Date getCreatioTime()
    {
        return creatioTime;
    }

    public void setCreatioTime(Date creatioTime)
    {
        this.creatioTime = creatioTime;
    }

    public Date getScheduleTime()
    {
        return scheduleTime;
    }

    public void setScheduleTime(Date scheduleTime)
    {
        this.scheduleTime = scheduleTime;
    }

    public int getMaxRetryTimes()
    {
        return maxRetryTimes;
    }

    public void setMaxRetryTimes(int maxRetryTimes)
    {
        this.maxRetryTimes = maxRetryTimes;
    }

    public Parameters getParams()
    {
        return params;
    }

    public void setParams(Parameters params)
    {
        this.params = params;
    }

    public void setObjectParam(String key, Object value)
    {
        if (params == null) {
            params = new SimpleParameters();
        }
        params.setObject(key, value);
    }

    public void setLongParam(String key, long value)
    {
        setObjectParam(key, value);
    }

    public void setIntParam(String key, int value)
    {
        setObjectParam(key, value);
    }

    public void setFloatParam(String key, float value)
    {
        setObjectParam(key, value);
    }

    public void setDoubleParam(String key, double value)
    {
        setObjectParam(key, value);
    }

    public void setBoolParam(String key, boolean value)
    {
        setObjectParam(key, value);
    }

    public void setStringParam(String key, String value)
    {
        setObjectParam(key, value);
    }

    public Object getObjectParam(String key, Object defValue)
    {
        return params == null ? defValue : params.getObject(key, defValue);
    }

    public long getLongParam(String key, long defValue)
    {
        return params == null ? defValue : params.getLong(key, defValue);
    }

    public int getIntParam(String key, int defValue)
    {
        return params == null ? defValue : params.getInt(key, defValue);
    }

    public float getFloatParam(String key, float defValue)
    {
        return params == null ? defValue : params.getFloat(key, defValue);
    }

    public double getDoubleParam(String key, double defValue)
    {
        return params == null ? defValue : params.getDouble(key, defValue);
    }

    public boolean getBoolParam(String key, boolean defValue)
    {
        return params == null ? defValue : params.getBoolean(key, defValue);
    }

    public String getStringParam(String key, String defValue)
    {
        return params == null ? defValue : params.getString(key, defValue);
    }
}
